
(defun dotspacemacs/layers ()
  "Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
  (defvar my/ignore-directory 'C:\msys64\home\Administrator\.emacs.d)
  (setq lsp-java--download-root "https://gitee.com/liujiacai/lsp-java/raw/master/install/"
        lsp-java-workspace-dir (expand-file-name "workspace" my/ignore-directory)
        dap-java-test-runner (expand-file-name "eclipse.jdt.ls/test-runner/junit-platform-console-standalone.jar" my/ignore-directory)
        ;; jdk8 isn't supported in latest version
        ;; https://github.com/emacs-lsp/lsp-java/issues/249
        lsp-java-jdt-download-url "https://download.eclipse.org/jdtls/milestones/0.57.0/jdt-language-server-0.57.0-202006172108.tar.gz")
  (setq-default
   dotspacemacs-distribution 'spacemacs
   dotspacemacs-enable-lazy-installation 'unused
   dotspacemacs-ask-for-lazy-installation t
   dotspacemacs-configuration-layer-path '()
   dotspacemacs-configuration-layers
   '(
     python
     nginx
     sql
     (java :variables java-backend 'lsp)
     markdown
     html
     tern
     typescript
     javascript
     java
     tide
     nginx
     ;; helm
     better-defaults
     emacs-lisp
     git
     org
     vue
     spell-checking
     syntax-checking
     )
   dotspacemacs-additional-packages '(
                                      ;;xref-js2
                                      ag
                                      yafolding
                                      vterm
                                      youdao-dictionary
                                      company-tabnine
                                      glsl-mode
                                      move-text
                                      )
   dotspacemacs-frozen-packages '()
   dotspacemacs-excluded-packages '(tern company-tern auto-completion flyspell)
   dotspacemacs-install-packages 'used-only))

(defun dotspacemacs/init ()
  "Initialization function.
This function is called at the very startup of Spacemacs initialization
before layers configuration.
You should not put any user code in there besides modifying the variable
values."
  (setq-default
   dotspacemacs-elpa-https t
   dotspacemacs-elpa-timeout 5
   dotspacemacs-check-for-update nil
   dotspacemacs-elpa-subdirectory nil
   dotspacemacs-editing-style 'emacs
   dotspacemacs-verbose-loading nil
   dotspacemacs-startup-banner 'official
   dotspacemacs-startup-lists '((recents . 5)
                                (projects . 7))
   dotspacemacs-startup-buffer-responsive t
   dotspacemacs-scratch-mode 'text-mode
   dotspacemacs-themes '( spacemacs-dark
                          )
   dotspacemacs-mode-line-theme '(doom )
   dotspacemacs-colorize-cursor-according-to-state t
   dotspacemacs-default-font '("Source Code Pro"
                               :size 20
                               :weight normal
                               :width normal
                               :powerline-scale 1.1)
   dotspacemacs-leader-key "SPC"
   dotspacemacs-emacs-command-key "SPC"
   dotspacemacs-ex-command-key ":"
   dotspacemacs-emacs-leader-key "M-m"
   dotspacemacs-major-mode-leader-key ","
   dotspacemacs-major-mode-emacs-leader-key "C-M-m"
   dotspacemacs-distinguish-gui-tab nil
   dotspacemacs-remap-Y-to-y$ nil
   dotspacemacs-retain-visual-state-on-shift t
   dotspacemacs-visual-line-move-text nil
   dotspacemacs-ex-substitute-global nil
   dotspacemacs-default-layout-name "Default"
   dotspacemacs-display-default-layout nil
   dotspacemacs-auto-resume-layouts t
   dotspacemacs-large-file-size 4
   dotspacemacs-auto-save-file-location "~/.emacs.d/autosaves"
   dotspacemacs-max-rollback-slots 5
   dotspacemacs-helm-resize nil
   dotspacemacs-helm-no-header nil
   dotspacemacs-helm-position 'bottom
   dotspacemacs-helm-use-fuzzy 'always
   dotspacemacs-enable-paste-transient-state nil
   dotspacemacs-which-key-delay 0.4
   dotspacemacs-which-key-position 'bottom
   dotspacemacs-loading-progress-bar t
   dotspacemacs-fullscreen-at-startup nil
   dotspacemacs-fullscreen-use-non-native nil
   dotspacemacs-maximized-at-startup t
   dotspacemacs-active-transparency 90
   dotspacemacs-inactive-transparency 90
   dotspacemacs-show-transient-state-title t
   dotspacemacs-show-transient-state-color-guide t
   dotspacemacs-mode-line-unicode-symbols t
   dotspacemacs-smooth-scrolling t
   dotspacemacs-line-numbers t
   dotspacemacs-folding-method 'evil
   dotspacemacs-smartparens-strict-mode nil
   dotspacemacs-smart-closing-parenthesis nil
   dotspacemacs-highlight-delimiters 'all
   dotspacemacs-persistent-server nil
   dotspacemacs-search-tools '("ag" "pt" "ack" "grep")
   dotspacemacs-default-package-repository nil
   dotspacemacs-whitespace-cleanup nil
   treemacs-width 20
   treemacs-wide-toggle-width 35
   treemacs-position "right"
   treemacs-width-is-initially-locked t
   ))

(defun dotspacemacs/user-init ()
  "Initialization function for user code.
It is called immediately after `dotspacemacs/init', before layer configuration
executes.
 This function is mostly useful for variables that need to be set
before packages are loaded. If you are unsure, you should try in setting them in
`dotspacemacs/user-config' first."

;; 下面的都搞到lock文件里去

;; 关闭签名检查
(setq package-check-signature nil)
(setq configuration-layer-elpa-archives
    '(("melpa-cn" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/")
      ("org-cn"   . "http://mirrors.tuna.tsinghua.edu.cn/elpa/org/")
      ("gnu-cn"   . "http://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/")
      ("nognu" . "https://elpa.nongnu.org/nongnu/")
      ))
  ;; (setq configuration-layer-elpa-archives
  ;;     '(("melpa-cn" . "http://1.15.88.122/melpa/")
  ;;       ("org-cn"   . "http://1.15.88.122/org/")
  ;;       ("gnu-cn"   . "http://1.15.88.122/gnu/")
  ;;       ("nongnu"       . "https://elpa.nongnu.org/nongnu/")))
;; (setq configuration-layer-elpa-archives
;;       `(("melpa" . ,(concat user-home-directory "elpa-mirror/melpa/"))
;;         ("org"   . ,(concat user-home-directory "elpa-mirror/org/"))
;;         ("gnu"   . ,(concat user-home-directory "elpa-mirror/gnu/"))))

;; (setq package-archives
;;       `(("melpa" . ,(concat user-home-directory "elpa-mirror/melpa/"))
;;         ("org"   . ,(concat user-home-directory "elpa-mirror/org/"))
;;         ("gnu"   . ,(concat user-home-directory "elpa-mirror/gnu/"))))
;; (package-initialize)
)

(defun dotspacemacs/user-config ()
  "Configuration function for user code.
This function is called at the very end of Spacemacs initialization after
layers configuration.
This is the place where most of your configurations should be done. Unless it is
explicitly specified that a variable should be set before a package is loaded,
you should place your code here."
  (setq create-lockfiles nil)

  (use-package yafolding
    :ensure
    :config
    (add-hook 'prog-mode-hook
              (lambda () (yafolding-mode)))
    (define-key yafolding-mode-map (kbd "<C-S-return>") nil)
    (define-key yafolding-mode-map (kbd "<C-M-return>") nil)
    (define-key yafolding-mode-map (kbd "<C-return>") nil)
    (define-key yafolding-mode-map (kbd "C-c <C-M-return>") 'yafolding-toggle-all)
    (define-key yafolding-mode-map (kbd "C-c <C-S-return>") 'yafolding-hide-parent-element)
    (define-key yafolding-mode-map (kbd "C-c <C-return>") 'yafolding-toggle-element)
    )

  ;; (use-package meghanada
  ;;   :ensure t
  ;;   :defer t
  ;;   :config
  ;;   (add-hook 'java-mode-hook
  ;;             (lambda ()
  ;;               ;; meghanada-mode on
  ;;               (setq c-basic-offset 4)
  ;;               (meghanada-mode t)
  ;;               (flycheck-mode +1)
  ;;               (setq c-basic-offset 2)
  ;;               ;; use code format
  ;;               ;; (add-hook 'before-save-hook 'meghanada-code-beautify-before-save)
  ;;               ))
  ;;   (cond
  ;;    ((eq system-type 'windows-nt)
  ;;     (setq meghanada-java-path (expand-file-name "bin/java.exe" (getenv "JAVA_HOME")))
  ;;     (setq meghanada-maven-path "mvn.cmd"))
  ;;    (t
  ;;     (setq meghanada-java-path "java")
  ;;     (setq meghanada-maven-path "mvn")))
  ;;   )

  (add-to-list 'auto-mode-alist '("\\.effect\\'" . glsl-mode))

  (setq auto-mode-alist
        (delete '("\\.m?js\\'" . js2-mode) auto-mode-alist))

  (setq auto-mode-alist
        (delete '("\\.js[mx]?\\'" . javascript-mode) auto-mode-alist))

  (add-to-list 'auto-mode-alist '("\\.js[mx]?\\'" . js-mode))
  (add-to-list 'auto-mode-alist '("\\.js\\'" . js-mode))

  (setq company-idle-delay 0.05)
  (setq company-minimum-prefix-length 1)
  (setq company-show-numbers t)

  (require 'yasnippet)
  (setq yas-snippet-dirs
        '(;; "~/.emacs.d/snippets"                 ;; personal snippets
          "~/.spacemacs.d/yasnippet-snippets/snippets"
          ))
  (yas-reload-all)

  (global-company-mode)
  (add-hook 'prog-mode-hook #'yas-minor-mode)

  (setq mac-option-modifier 'meta) (setq mac-command-modifier nil)

  (defun setup-vue-mode()
    (setq web-mode-code-indent-offset 2)
    (setq web-mode-css-indent-offset 2)
    (setq web-mode-markup-indent-offset 2)
    (setq web-mode-style-padding 0)
    (setq web-mode-script-padding 0)
    (setq web-mode-block-padding 0)
    )

  (add-hook 'vue-mode-hook 'setup-vue-mode)

  ;; 代码检查
  (use-package flycheck
    :ensure t
    :init (global-flycheck-mode))


  (defun setup-tide-mode()
    "Setup funciton fot tide"
  	(interactive)
    (tide-setup)
    (flycheck-mode +1)
    (setq flycheck-check-syntax-automatically '(save mode-enabled))
    (tide-hl-identifier-mode +1)
    (company-mode +1)
    (add-to-list 'company-backends #'company-tabnine)
    )

  ;; 优化gc
  (defmacro k-time (&rest body)
    "Measure and return the time it takes evaluating BODY."
    `(let ((time (current-time)))
       ,@body
       (float-time (time-since time))))

  (defvar k-gc-timer
    (run-with-idle-timer 15 t
                         (lambda ()
                           (message "Garbage Collector has run for %.06fsec"
                                    (k-time (garbage-collect))))))

  (add-hook 'js-mode-hook #'setup-tide-mode)
  (add-hook 'js-mode-hook 'flycheck-mode)

  ;; (spacemacs/toggle-automatic-symbol-highlight-on)

  ;;(global-set-key (kbd "M-m t t") 'dumb-jump-go)
  ;;(global-set-key (kbd "M-m t b") 'dumb-jump-back)
  (global-set-key (kbd "M-m t t") 'treemacs-select-window)
  (global-set-key (kbd "C-=") 'mc/mark-next-like-this)
  (global-set-key (kbd "C-;") 'set-mark-command)
  (global-set-key (kbd "C-s") 'helm-swoop)
  (global-set-key (kbd "M-m s p") 'projectile-ag)
  (global-set-key (kbd "M-<up>") 'move-text-up)
  (global-set-key (kbd "M-<down>") 'move-text-down)
  (global-set-key (kbd "M-m p f") 'project-find-file)

  ;; create the autosave dir if necessary, since emacs won't.
  (make-directory "~/.emacs.d/autosaves/" t)
  (make-directory "~/.emacs.d/backups/" t)
  (make-directory "~/org-notes/" t)
  ;; (setq projectile-project-search-path '("~/work/fcool/proj"))

  (setq-default indent-tabs-mode nil)
  (setq-default tab-width 4)
  (setq indent-line-function 'insert-tab)


  ;; 双击打开电脑上的文件时，emacs不重新打开新的emacs客户端程序
  (setq ns-pop-up-frames nil)
  ;; org
  (setq org-agenda-files '("~/org-notes/"))
  (setq org-capture-templates
        '(("t" "Todo" entry (file+headline "~/org-notes/gtd.org" "Tasks")
           "* TODO %?\n %i\n %a")
          ("j" "Journal" entry (file+datetree "~/org-notes/journal.org")
           "* %?\nEntered on %U\n %i\n %a")))
  
  (setq org-agenda-custom-commands
        '(
          ("w" . "任务安排")
          ("wa" "重要且紧急的任务" tags-todo "+PRIORITY=\"A\"")
          ("wb" "重要且不紧急的任务" tags-todo "-weekly-monthly-daily+PRIORITY=\"B\"")
          ("wc" "不重要且紧急的任务" tags-todo "+PRIORITY=\"C\"")
          ("W" "Weekly Review"

           ((stuck "") ;; review stuck projects as designated by org-stuck-projects
            (tags-todo "project")
            (tags-todo "daily")
            (tags-todo "weekly")
            (tags-todo "code")
            (tags-todo "theory")
            ))
          ))
  (setq org-todo-keywords
        '(
          (sequence "TODO(t!)" "DONE(d!)")
          (sequence "CLOSE(a@/!)" "WAITTING(w)")
          ))
  
  (setq doom-modeline-buffer-file-name-style 'truncate-upto-project)
  
  (setq markdown-command "pandoc")
  ;; 窗口和自动黄金比例
  (spacemacs/toggle-golden-ratio-on)

  (global-set-key (kbd "C-q") 'youdao-dictionary-search-at-point+)


  ;; 显示缩进线
  (spacemacs/toggle-indent-guide-globally-on)

  
  )

(defun dotspacemacs/emacs-custom-settings ()
  "Emacs custom settings.
This is an auto-generated function, do not modify its content directly, use
Emacs customize menu instead.
This function is called at the very end of Spacemacs initialization."
(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(auto-save-file-name-transforms '((".*" "~/.emacs.d/autosaves/" t)))
 '(backup-directory-alist '((".*" . "~/.emacs.d/backups/")))
 '(company-backends
   '(company-tide company-bbdb company-semantic company-clang company-cmake company-capf company-files
                  (company-dabbrev-code company-gtags company-etags company-keywords)
                  company-oddmuse company-dabbrev))
 '(gc-cons-threshold 2000000000)
 '(package-selected-packages
   '(yafolding emr company-tabnine ace-jump-helm-line ace-link ag aggressive-indent anaconda-mode packed auto-dictionary auto-highlight-symbol blacken centered-cursor-mode clean-aindent-mode code-cells column-enforce-mode company cython-mode define-word devdocs dired-quick-sort shrink-path drag-stuff drupal-mode dumb-jump editorconfig elisp-def elisp-slime-nav emmet-mode list-utils eval-sexp-fu anzu evil-args paredit annalist evil-ediff evil-escape evil-exchange evil-goggles iedit evil-indent-plus evil-lion evil-lisp-state evil-matchit evil-nerd-commenter evil-numbers evil-org evil-surround evil-textobj-line evil-tutor evil-visual-mark-mode evil-visualstar expand-region eyebrowse fancy-battery flx-ido flycheck-elsa package-lint flycheck-pos-tip flyspell-correct-helm flyspell-correct geben gh-md git-link git-messenger git-modes git-timemachine gitignore-templates glsl-mode gnuplot golden-ratio google-translate helm-ag helm-css-scss helm-descbinds helm-flx flx helm-git-grep helm-ls-git helm-make helm-mode-manager helm-org helm-org-rifle helm-projectile helm-purpose helm-pydoc helm-swoop helm-themes helm-xref helm helm-core highlight-indentation highlight-numbers php-auto-yasnippets youdao-dictionary yapfify ws-butler writeroom-mode winum window-purpose which-key web-mode web-beautify vterm volatile-highlights vim-powerline vi-tilde-fringe uuidgen use-package unfill undo-tree treemacs-projectile treemacs-persp treemacs-magit treemacs-icons-dired toc-org tide term-cursor tagedit symon symbol-overlay string-inflection string-edit sql-indent sphinx-doc spacemacs-whitespace-cleanup spacemacs-purpose-popwin spaceline-all-the-icons space-doc smeargle smartparens slim-mode scss-mode sass-mode restart-emacs request rainbow-delimiters quickrun pytest pylookup pyenv-mode pydoc py-isort pug-mode prettier-js popwin poetry pippel pipenv pip-requirements phpunit phpcbf phpactor php-extras pcre2el password-generator parent-mode paradox overseer orgit org-superstar org-rich-yank org-projectile org-present org-pomodoro org-mime org-download org-cliplink open-junk-file npm-mode nose nodejs-repl nginx-mode nameless mwim multi-line mmm-mode markdown-toc macrostep lorem-ipsum livid-mode live-py-mode link-hint json-reformat json-navigator json-mode js2-refactor js-doc inspector info+ indent-guide importmagic impatient-mode hybrid-mode hungry-delete holy-mode hl-todo highlight-parentheses hide-comnt help-fns+ font-lock+ evil-evilified-state dotenv-mode diminish bind-map))
 '(warning-suppress-types '((use-package))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(highlight-parentheses-highlight ((nil (:weight ultra-bold))) t))
)
